﻿using ClassMetadataBrowser.Domain;
using ClassMetadataBrowser.Domain.Metadata;
using System.Drawing;
using System.Windows.Media.Imaging;
using System.Collections.Generic;
using System.IO;
using System.Drawing.Imaging;

namespace ClassMetadataBrowser
{
	internal class MetadataImage : IMetadataVisitor
	{
		private static Dictionary<Bitmap, BitmapImage> _cache = new Dictionary<Bitmap, BitmapImage>();

		public Bitmap Icon
		{
			get;
			private set;
		}

		#region IMetadataVisitor Members

		void IMetadataVisitor.Visit(ClassMetadata obj)
		{
			if (obj.IsInternal)
				Icon = Icons.ClassFriend;
			else if (obj.IsPrivate)
				Icon = Icons.ClassPrivate;
			else if (obj.IsProptected)
				Icon = Icons.ClassProtected;
			else
				Icon = Icons.Class;
			// TODO: Sealed Icon
		}

		void IMetadataVisitor.Visit(DelegateMetadata obj)
		{
			if (obj.IsInternal)
				Icon = Icons.DelegateFriend;
			else if (obj.IsPrivate)
				Icon = Icons.DelegatePrivate;
			else if (obj.IsProptected)
				Icon = Icons.DelegateProtected;
			else
				Icon = Icons.Delegate;
		}

		void IMetadataVisitor.Visit(EnumMetdata obj)
		{
			if (obj.IsInternal)
				Icon = Icons.DelegateFriend;
			else if (obj.IsPrivate)
				Icon = Icons.DelegatePrivate;
			else if (obj.IsProptected)
				Icon = Icons.DelegateProtected;
			else
				Icon = Icons.Delegate;
		}

		void IMetadataVisitor.Visit(EventMetadata obj)
		{
			if (obj.IsInternal)
				Icon = Icons.EventFriend;
			else if (obj.IsPrivate)
				Icon = Icons.EventPrivate;
			else if (obj.IsProptected)
				Icon = Icons.EventProtected;
			else
				Icon = Icons.Event;
		}

		void IMetadataVisitor.Visit(InterfaceMetdata obj)
		{
			if (obj.IsInternal)
				Icon = Icons.InterfaceFriend;
			else if (obj.IsPrivate)
				Icon = Icons.InterfacePrivate;
			else if (obj.IsProptected)
				Icon = Icons.InterfaceProtected;
			else
				Icon = Icons.Interface;
		}

		void IMetadataVisitor.Visit(MethodMetadata obj)
		{
			if (obj.IsInternal)
				Icon = Icons.MethodFriend;
			else if (obj.IsPrivate)
				Icon = Icons.MethodPrivate;
			else if (obj.IsProptected)
				Icon = Icons.MethodProtected;
			else
				Icon = Icons.Method;
		}

		void IMetadataVisitor.Visit(PropertyMetadata obj)
		{
			if (obj.IsInternal)
				Icon = Icons.PropertyFriend;
			else if (obj.IsPrivate)
				Icon = Icons.PropertyPrivate;
			else if (obj.IsProptected)
				Icon = Icons.PropertyProtected;
			else
				Icon = Icons.Property;
		}

		void IMetadataVisitor.Visit(StructMetadata obj)
		{
			if (obj.IsInternal)
				Icon = Icons.StructFriend;
			else if (obj.IsPrivate)
				Icon = Icons.StructPrivate;
			else if (obj.IsProptected)
				Icon = Icons.StructProtected;
			else
				Icon = Icons.Struct;
		}

		#endregion
	}
}
